package com.hue.concurrent.day01;

/*
    线程的睡眠和打断:
        当线程调用sleep后进入睡眠状态，其他线程可以调用这个线程的interrupt方法打断睡眠，
        但是被打断的线程会抛出异常
    sleep会让当前线程从running状态变为timed waiting状态
    如果线程的打断标记为true，会直接抛出异常
 */
public class Demo05 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("t1执行...");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t1被打断...");
        }, "t1");

        t1.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t1.interrupt();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("打断标记:"+t1.isInterrupted());
    }
}
